class ArrayIterator
  def initialize(array)
    @array, @index = array, 0
  end
  
  def has_next?
    @index < @array.size
  end
  
  def item
    @array[@index]
  end
  
  def next_item
    value = @array[@index]
    @index += 1
    value
  end
end

array = ["red", "green", "yellow"]
i = ArrayIterator.new(array)

while i.has_next? do
  puts "item: #{i.next_item}"
end

class Account
  attr_accessor :name, :balance
  
  def initialize(name, balance)
    @name, @balance = name, balance
  end
  
  def <=>(other)
    balance <=> other.balance
  end
end

class Portfilio
  include Enumerable
  
  def initialize
    @accounts = []
  end
  
  def each(&block)
    @accounts.each(&block)
  end
  
  def add_account(account)
    @accounts << account
  end
end